package com.xaicode.template.gendata.mall.model;

import com.xaicode.template.gendata.mall.common.RandomNum;
import com.xaicode.template.gendata.mall.common.RandomNumString;
import com.xaicode.template.gendata.mall.common.RandomOptionGroup;
import com.xaicode.template.gendata.mall.config.AppConfig;
import com.xaicode.template.gendata.mall.enums.DisplayType;
import com.xaicode.template.gendata.mall.enums.ItemType;
import com.xaicode.template.gendata.mall.enums.PageId;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author Locker xaicode@sina.com
 * @version 1.0
 * @date 2022/5/24 0024 21:49
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AppPage {

    PageId last_page_id;
    PageId page_id;
    ItemType item_type;
    String item;

    Integer during_time;
    String extend1;
    String extend2;
    DisplayType source_type;

    public static AppPage build(PageId pageId, PageId lastPageId, Integer duringTime) {
        ItemType itemType = null;
        String item = null;
        String extend1 = null;
        String extend2 = null;
        DisplayType sourceType = null;

        RandomOptionGroup<DisplayType> sourceTypeGroup = RandomOptionGroup.builder()
                .add(DisplayType.query, AppConfig.sourceTypeRate[0].intValue())
                .add(DisplayType.promotion, AppConfig.sourceTypeRate[1].intValue())
                .add(DisplayType.recommend, AppConfig.sourceTypeRate[2].intValue())
                .add(DisplayType.activity, AppConfig.sourceTypeRate[3].intValue())
                .build();

        if (pageId == PageId.good_detail || pageId == PageId.good_spec
                || pageId == PageId.comment || pageId == PageId.comment_list) {
            sourceType = (DisplayType) sourceTypeGroup.getValue();
            itemType = ItemType.sku_id;
            item = RandomNum.getRandInt(1, AppConfig.max_sku_id) + "";
        } else if (pageId == PageId.good_list) {
            itemType = ItemType.keyword;
            item = (new RandomOptionGroup(AppConfig.searchKeywords)).getRandStringValue();
        } else if (pageId == PageId.trade || pageId == PageId.payment || pageId == PageId.payment_done) {
            itemType = ItemType.sku_ids;
            item = RandomNumString.getRandNumString(1, AppConfig.max_sku_id, RandomNum.getRandInt(1, 3), ",", false);
        }
        return new AppPage(lastPageId, pageId, itemType, item, duringTime, extend1, extend2, sourceType);
    }
}
